import Vue from 'vue'
import { USER_INFO, APP_THEME, APP_BACKGOURND, APP_OPACITY, APP_BACKGOURND_HTTP } from '@/store/mutation-types'
const getters = {
  sidebar: state => state.app.sidebar,
  size: state => state.app.size,
  device: state => state.app.device,
  visitedViews: state => state.tagsView.visitedViews,
  cachedViews: state => state.tagsView.cachedViews,
  token: state => state.user.token,
  avatar: state => state.user.avatar,
  nums:state => state.user.num,
  name: state => {
    if (!state.user.name) {
      let userInfo = JSON.parse(Vue.ls.get(USER_INFO) || {})
      state.user.name = userInfo.userName
    }
    return state.user.name
  },
  niceName: state => {
    if (!state.user.niceName) {
      let userInfo = JSON.parse(Vue.ls.get(USER_INFO) || {})
      state.user.niceName = userInfo.nickName
    }
    return state.user.niceName
  },
  introduction: state => state.user.introduction,
  roles: state => state.user.roles,
  permissions: state => state.user.permissions,
  permission_routes: state => state.permission.routes,
  sidebarRouters: state => state.permission.sidebarRouters,
  primaryColor: state => {
    let color = Vue.ls.get(APP_THEME)
    if (color) {
      state.app.color = color
    }
    return state.app.color
  },
  bgPath: state => {
    let bgPath = Vue.ls.get(APP_BACKGOURND)
    if (bgPath) {
      state.app.bgPath = bgPath
    }
    return state.app.bgPath
  },
  httpPath: state => {
    let httpBgPath = Vue.ls.get(APP_BACKGOURND_HTTP)
    if (httpBgPath) {
      state.app.httpBgPath = httpBgPath
    }
    return state.app.httpBgPath
  },
  opacityValue: state => {
    let opacity = Vue.ls.get(APP_OPACITY)
    if (opacity) {
      state.app.opacity = opacity
    }
    return state.app.opacity
  }
}
export default getters
